<?php
// vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldclose=all foldmethod=marker:
/**
 * 项目：   5anet
 * 文件：   class/soft/Download.class.php
 *
 * 下载软件
 *
 * PHP Version 5
 *
 * @package:   class.article
 * @author:    Mike.G Chinese Name: 黄叶 <hylinux@gmail.com>
 * @license:   http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1 
 * @copyright: www.5anet.com
 * @version:   $Id: $
 * @date:      $Date: $
 */

include_once CLASS_PATH.'main/BaseAction.class.php';

class Download extends BaseAction {

   /**
    * 数据库的连接
    */
   private $db;

   /**
    * 构造函数
    * @param:  NULL
    * @return: NULL
    * @access: public
    */
   public function __construct() {
      $this->db = $this->getDB();
   }

   /**
    * 下载软件
    * @param:  NULL
    * @return: NULL
    * @access: public
    * @static
    */
   public function run() {
      //文章的id
      $id = $this->getParameter('id');

      if ( !$id || strlen($id) == 0 ) {
         echo "没有指定需下载的软件。\n";
         return;
      }

      //更新下载次数
      $sql = 'update soft set downloads = downloads + 1 where id=?';
      $sth = $this->db->prepare($sql);
      $this->db->Execute($sth, array($id));

      $sql = 'select downloadurl from soft where id=?';
      $sth = $this->db->prepare($sql);
      $res = $this->db->Execute($sth, array($id));
      $rows = $res->FetchRow();


      //下载软件
      header('location:'.ROOT_URL.'upload/soft/'.$rows['downloadurl']);



   }
}


?>
